<?php

namespace app\index\controller;

use app\admin\model\Classifymodel;
use app\BaseController;
use think\App;
use think\exception\ValidateException;

class Common extends BaseController
{
    protected $validate;           //全局验证
    protected $catmodel;
    protected $showData;

    public function __construct(App $app)
    {
        $this->catmodel = new Classifymodel();
        parent::__construct($app);
        $this->middleware = [];
    }

    public function index(){
        $this->showData['controller'] = $this->request->controller();
        $this->showData['dateArr'] = $this->getDateInfo();
        $this->showData['menuList'] = $this->catmodel->findAllInfo('id, name', [['fid', '=', 29], ['status', '=', 1]]);
    }

    public function getDateInfo(){

        //每日一句日期获取
        $date = date("Y-m-d-H-i-s", time());
        $dateArr = explode('-', $date);

        $dayArr = array("日","一","二","三","四","五","六");
        $dateArr['day'] = $dayArr[date("w")];

        return $dateArr;
    }

    /**
     * 全局验证
     * @param $data                待验证数组
     * @param string $scene        验证识别标识
     * @return array|string
     */
    protected function checkData($data, $scene = ''){
        try {
            validate($this->validate)->scene($scene)->check($data);
        } catch (ValidateException $e) {
            return $e->getError();
        }
    }

}
